package com.lm.jasync.config;

import com.github.jasync.sql.db.mysql.pool.MySQLConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JasyncConfig {

    @Bean
    public MySQLConnectionFactory mysqlConnectionFactory(
            @Value("${jasync.mysql.host}") String host,
            @Value("${jasync.mysql.port}") int port,
            @Value("${jasync.mysql.database}") String database,
            @Value("${jasync.mysql.username}") String username,
            @Value("${jasync.mysql.password}") String password
    ) {
        com.github.jasync.sql.db.Configuration jasyncConfig =
                new com.github.jasync.sql.db.Configuration(
                        username,
                        host,
                        port,
                        password,
                        database
                );

        return new MySQLConnectionFactory(jasyncConfig);
    }
}

